package com.meihua.shellapp.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.EditText;

import com.meihua.shellapp.R;

/**
 * 作者：lc on 2017/9/30.
 * 邮箱：lc0607live@163.com
 */

public class MyOnclickEditText extends android.support.v7.widget.AppCompatEditText {

    public MyOnclickEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * 设置EditText可编辑状态
     *
     * @param focusable
     * @param focusable
     * @param gravity
     */
    public void setFocusableAndGravity(boolean focusable, int gravity) {
        setFocusable(focusable);
        setFocusableInTouchMode(focusable);
        if (gravity == Gravity.LEFT) {
            if (focusable == false) {
                Drawable temp = getResources().getDrawable(R.drawable.xiala);
                temp.setBounds(0, 0, 44, 44);
                setCompoundDrawables(null, null, temp, null);
            } else {
                setCompoundDrawables(null, null, null, null);
            }
            setEnabled(true);
        } else {
            setEnabled(false);
            setCompoundDrawables(null, null, null, null);
        }
        this.setGravity(gravity | Gravity.CENTER_VERTICAL);
    }
}
